<%@page contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head>
    <title>栏目管理</title>
	<%@ include file="/common/header/meta.jsp"%>
	<%@ include file="/common/header/script.jsp"%>
    <script type="text/javascript">
    var $tree, $parent_box ;
    $(function(){
    	$parent_box = $("#pid").combotree({
			url : $.webapp.root + "/admin/site/column/combo_tree.do",
			idFiled:'pid', textFiled:'name', editable: false, required:false, lines:true, autoShowPanel: false
		}) ;
    	
		$tree = $("#tree").tree({
			url: $.webapp.root + "/admin/site/column/doNotNeedAuth_tree.do",
			method: "get", animate: true, idField: 'id', treeField: 'colName',
			onClick: function(node){
				var form_url = $.webapp.root + "/admin/site/column/get.do" ;
				$.post(form_url, {id: node.id}, function(result) {
					$('form').form('load',result);
					if(undefined == result.pid) {
						$parent_box.combotree("setValue", "");
					}
				}, 'json').error(function(){$.easyui.loaded();});
				
		    }
		});    
    });
    
    
    function add() {
    	$("#form").form("clear") ;
    }
    
    function save() {
    	if($('#form').form('validate')) {
			$.easyui.loading({ msg: "数据提交中，请稍等..." });
			
			var form_url = $.webapp.root + "/admin/site/column/add.do" ;
	    	if($('input[name=id]').val().length > 0) {
				form_url = $.webapp.root + "/admin/site/column/update.do" ;
	    	}
	    	$.post(form_url, $("#form").form("getData"), function(result) {
				if (result.status) {
					$tree.tree("reload") ;
					$.easyui.loaded();
				} else {
					$.easyui.loaded();$.messager.alert("错误", result.msg, "error");
				}
			}, 'json').error(function(){$.easyui.loaded();});
		} 
    }
    
    function del() {
    	var node = $tree.tree('getSelected');
		if(node){
			$.messager.confirm("该操作不可逆，您确定要进行该操作？", function (c) { 
				if(c) {
					$.easyui.loading({ msg: "数据删除中，请稍等..." });
					$.post($.webapp.root + "/admin/site/column/delete.do", {id:node.id}, function(result) {
						if (result.status) {
							$("#form").form("clear");
							$tree.tree('reload');$.easyui.loaded();
							alertify.success(result.msg);
						} else {
							$.easyui.loaded();alertify.error(result.msg);
						}
					}, 'json').error(function(){$.easyui.loaded();});
				} else {}
			});
		} else {
			alertify.warning("请选择一条记录！");
		}
    }
    
    </script>
</head>

<body>
	<div class="easyui-layout" data-options="fit:true">
		
		<div data-options="region:'west',split:true" style="width:330px;border-top:none;">
			<div class="easyui-layout" data-options="fit:true"> 
				<div data-options="region:'center',border:false,iconCls:'icon-hamburg-category'" title="栏目列表">
					<div id="tree"></div>
				</div>
			</div>
		</div>
		
		<div data-options="region:'center',border:false">
			<div class="easyui-layout" data-options="fit:true">
			
				<div data-options="region: 'north', split: false, border: true" style="border-top:none;height: 33px;">
	                <div class="easyui-toolbar">
	                    <a onClick="add();" class="easyui-linkbutton" data-options="plain: true, iconCls: 'ext_add'">新增</a>
	                    <a onClick="save()" class="easyui-linkbutton" data-options="plain: true, iconCls: 'ext_save'">保存</a>
	                    <a onClick="del()" class="easyui-linkbutton" data-options="plain: true, iconCls: 'ext_remove'">删除</a>
	                </div>
	            </div>
				<div data-options="region:'center'">
					<form id="form" class="easyui-form form_container">
						<input type="hidden" name="id" value="${id}" />
						<input type="hidden" name="modifyName" value="${USER_SESSION.user.emp_name}" />
						<table class="tableform">
							<tr>
								<th>栏目名称：</th>
								<td><input name="colName" class="easyui-validatebox" type="text" data-options="required: true" /></td>
							</tr>
							<tr>
								<th>栏目别名：</th>
								<td><input name="colAlias" class="easyui-validatebox" type="text" data-options="" /></td>
							</tr>
							<tr>
								<th>栏目类型：</th>
								<td><input name="colType" class="easyui-validatebox" type="text" data-options="" /></td>
							</tr>
							<tr>
								<th>栏目URL：</th>
								<td><input name="colUrl" class="easyui-validatebox" type="text" data-options="" /></td>
							</tr>
							<tr>
								<th>栏目级别：</th>
								<td><input name="colLevel" class="easyui-validatebox" type="text" data-options="" /></td>
							</tr>
							<tr>
								<th>上级栏目：</th>
								<td><input id="pid" name="pid" style="width:219px;height:25px;"></input></td>
							</tr>
						</table>
					</form>
				</div>
				
			</div>
		</div>
		
	</div>
    
</body>
</html>



